<!-- 车辆管理 -->
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @selection-change="selectionChange"
    >
      <template slot-scope="{ disabled, size }" slot="expireDateSearch">
        <el-switch :disabled="disabled" :size="size" v-model="query.expireDate">
        </el-switch>
      </template>
      <template slot="menuLeft">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="small"
          @click="batchDelete"
          >删除</el-button
        >
        <importBtn
          customUrl="/api/blade-tms/car/CarManagementController/importIntoExcel"
          @refresh="onLoad(page)"
        />
        <downTemplateBtn
          customUrl="/api/blade-tms/car/CarManagementController/export"
        />
      </template>
      <template slot-scope="{ row, index }" slot="menu">
        <el-button
          type="text"
          size="mini"
          icon="el-icon-edit"
          @click.stop="rowEdit(row, index)"
          >编辑</el-button
        >
        <el-button
          type="text"
          size="mini"
          icon="el-icon-view"
          v-if="row.approvalStatus == '已驳回'"
          @click.stop="viewReject(row)"
          >驳回原因</el-button
        >
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import { getList, update, deleteCar } from "@/api/basedata/car";
import { phoneBind } from "@/api/basedata/carriers";
import importBtn from "../components/importBtn";
import downTemplateBtn from "../components/downTemplateBtn";

export default {
  data() {
    return {
      form: {
        transportGoodsType: "",
      },
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      data: [],
      selectionList: [], //选择数据
    };
  },
  components: { importBtn, downTemplateBtn },
  watch: {
    "form.carType"(val) {
      if (val === "trailer") {
        this.form.gpsEquipmentNumber = "";
        this.form.carNo = "";
        this.form.certificationCarTransportNo = "";
        this.form.certificationCarCheckValid = [];
        this.form.certificationCarWorkNo = "";
        this.form.certificationCarWorkValid = [];
        this.form.carTransportPic = "";
        this.form.carWorkPic = "";
        this.form.certificateTankTruck = "";
      } else if (val === "tractor") {
        this.form.bindCarNo = "";
        this.form.certificationBindCarTransportNo = "";
        this.form.certificationBindCarCheckValid = [];
        this.form.certificationBindCarWorkNo = "";
        this.form.certificationBindCarWorkValid = [];
        this.form.bindCarTransportPic = "";
        this.form.bindCarWorkPic = "";
        this.form.certificateTankTruckDate = [];
      }
    },
    "query.expireDate"(val) {
      if (val === false || val === true) {
        this.page.currentPage = 1;
        this.onLoad(this.page, this.query);
      }
    },
  },
  computed: {
    //是否为挂车
    isTrailer() {
      return this.form.carType === "trailer";
    },
    //是否为牽引車
    isTractor() {
      return this.form.carType === "tractor";
    },
    option() {
      var validateNum = (rule, value, callback) => {
        if (
          value !== "" &&
          !/(^[1-9]\d*(\.\d{1,4})?$)|(^0(\.\d{1,4})?$)/.test(value)
        ) {
          callback(new Error("格式不正确,请输入大于等于0,小数点后4位！"));
        } else {
          callback();
        }
      };
      return {
        tabs: true,
        tabsActive: 1,
        height: "auto",
        calcHeight: 30,
        tip: false,
        selection: true,
        searchShow: false,
        searchMenuSpan: 6,
        border: true,
        editBtn: false,
        labelWidth: "180",
        menuWidth: "250",
        column: [
          {
            label: "车牌照号",
            prop: "carNo",
            search: true,
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "挂车号",
            prop: "bindCarNo",
            search: true,
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "车辆类型",
            prop: "carType",
            type: "select",
            props: {
              label: "value",
              value: "key",
            },
            search: true,
            dicUrl: `/api/blade-tms/common/SelectEnum?name=car`,
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "普货/危化品",
            searchLabelWidth: "100",
            prop: "transportGoodsType",
            type: "select",
            props: {
              label: "value",
              value: "key",
            },
            search: true,
            dicUrl: `/api/blade-tms/common/SelectEnum?name=CargoType`,
            dicMethod: "get",
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "牵引车行驶证号",
            prop: "certificationCarTransportNo",
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "挂车行驶证号",
            prop: "certificationBindCarTransportNo",
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "车架号/车辆识别码",
            prop: "carFlag",
            editDisplay: false,
            addDisplay: false,
          },
          {
            label: "审核状态",
            prop: "approvalStatus",
            type: "select",
            editDisplay: false,
            addDisplay: false,
            props: {
              label: "value",
              value: "key",
            },
            search: true,
            dicUrl: `/api/blade-tms/common/SelectEnum?name=approval`,
          },
          {
            label: "创建时间",
            type: "datetime",
            prop: "createTime",
            search: true,
            searchRange: true,
            editDisplay: false,
            addDisplay: false,
            hide: true,
            showColumn: false,
            defaultTime: ["00:00:00", "23:59:59"],
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            startPlaceholder: "请选择开始日期",
            endPlaceholder: "请选择结束日期",
          },
          {
            label: "即将到期",
            prop: "expireDate",
            search: true,
            searchRange: true,
            editDisplay: false,
            addDisplay: false,
            hide: true,
            showColumn: false,
            searchSpan: 3,
          },
        ],
        group: [
          {
            label: "资质信息",
            prop: "qualifications",
            column: [
              {
                label: "车辆类型",
                prop: "carType",
                type: "select",
                props: {
                  label: "value",
                  value: "key",
                },
                dicUrl: `/api/blade-tms/common/SelectEnum?name=car`,
                rules: [
                  {
                    required: true,
                    message: "请选择车辆类型",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "普货/危化品",
                searchLabelWidth: "100",
                prop: "transportGoodsType",
                type: "select",
                props: {
                  label: "value",
                  value: "key",
                },
                dicUrl: `/api/blade-tms/common/SelectEnum?name=CargoType`,
                dicMethod: "get",
                rules: [
                  {
                    required: !this.isTrailer,
                    message: "请选择普货/危化品",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "车牌照号",
                prop: "carNo",
                display: !this.isTrailer,
                rules: [
                  {
                    required: !this.isTrailer,
                    message: "请输入车牌照号",
                    trigger: "blur",
                  },
                ],
              },
              {
                label: "挂车号",
                prop: "bindCarNo",
                display: !this.isTractor,
                rules: [
                  {
                    required: this.isTrailer,
                    message: "请输入挂车号",
                    trigger: "blur",
                  },
                ],
              },
              {
                label: "牵引车行驶证号",
                prop: "certificationCarTransportNo",
                display: !this.isTrailer,
                rules: [
                  {
                    required: !this.isTrailer,
                    message: "请输入牵引车行驶证号",
                    trigger: "blur",
                  },
                ],
              },
              {
                label: "牵引车校验有效期",
                prop: "certificationCarCheckValid",
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
                display: !this.isTrailer,
                rules: [
                  {
                    required: !this.isTrailer,
                    message: "请选择牵引车校验有效期",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "挂车行驶证号",
                prop: "certificationBindCarTransportNo",
                display: !this.isTractor,
                rules: [
                  {
                    required: this.isTrailer,
                    message: "请输入挂车行驶证号",
                    trigger: "blur",
                  },
                ],
              },
              {
                label: "挂车校验有效期",
                prop: "certificationBindCarCheckValid",
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
                display: !this.isTractor,
                rules: [
                  {
                    required: this.isTrailer,
                    message: "请选择挂车校验有效期",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "牵引车营运证号",
                prop: "certificationCarWorkNo",
                hide: true,
                showColumn: false,
                display: !this.isTrailer,
                rules: [
                  {
                    required: !this.isTrailer,
                    message: "请输入牵引车营运证号",
                    trigger: "blur",
                  },
                ],
              },
              {
                label: "牵引车营运证号有效期",
                prop: "certificationCarWorkValid",
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
                display: !this.isTrailer,
                rules: [
                  {
                    required: !this.isTrailer,
                    message: "请选择牵引车营运证号有效期",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "挂车营运证号",
                prop: "certificationBindCarWorkNo",
                hide: true,
                showColumn: false,
                display: !this.isTractor,
                rules: [
                  {
                    required: this.isTrailer,
                    message: "请输入挂车营运证号",
                    trigger: "blur",
                  },
                ],
              },
              {
                label: "挂车营运证号有效期",
                prop: "certificationBindCarWorkValid",
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
                display: !this.isTractor,
                rules: [
                  {
                    required: this.isTrailer,
                    message: "请选择挂车营运证号有效期",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "发动机号",
                prop: "engineNumber",
                display: !this.isTrailer,
              },
              {
                label: "车架号/车辆识别码",
                prop: "carFlag",
                rules: [
                  {
                    required: true,
                    message: "请输入车架号/车辆识别码",
                    trigger: "blur",
                  },
                ],
              },
              {
                label: "车辆排放阶段",
                prop: "emissionStage",
                hide: true,
                showColumn: false,
              },
              {
                label: "交强险",
                prop: "vehicleInsurance",
                hide: true,
                showColumn: false,
              },
              {
                label: "交强险有效期",
                prop: "vehicleInsuranceValid",
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
              },
              {
                label: "罐体报告编号",
                prop: "containerNo",
                hide: true,
                showColumn: false,
                // rules: [
                //   {
                //     required: true,
                //     message: "请输入罐体报告编号",
                //     trigger: "blur",
                //   },
                // ],
              },
              {
                label: "罐体报告有效期",
                prop: "containerReportValid",
                type: "datetimerange",
                hide: true,
                showColumn: false,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
                // rules: [
                //   {
                //     required: true,
                //     message: "请选择罐体报告有效期",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "是否启用GPS",
                prop: "enableGps",
                type: "select",
                hide: true,
                showColumn: false,
                dicData: [
                  {
                    label: "是",
                    value: "是",
                  },
                  {
                    label: "否",
                    value: "否",
                  },
                ],
              },
              {
                label: "GPS设备号",
                prop: "gpsEquipmentNumber",
                hide: true,
                showColumn: false,
                display: !this.isTrailer,
                rules: [
                  {
                    required:
                      this.form.transportGoodsType === "generalMerchandise",
                    message: "请输入GPS设备号",
                    trigger: "blur",
                  },
                ],
              },
              {
                label: "气罐车使用证",
                prop: "certificateTankTruck",
                hide: true,
                showColumn: false,
                display: !this.isTrailer,
                // rules: [
                //   {
                //     required: !this.isTrailer,
                //     message: "请输入气罐车使用证",
                //     trigger: "blur",
                //   },
                // ],
              },
              {
                label: "压力容器有效期",
                prop: "certificateTankTruckDate",
                type: "datetimerange",
                hide: true,
                showColumn: false,
                display: !this.isTractor,
                defaultTime: ["00:00:00", "23:59:59"],
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
                startPlaceholder: "请选择开始日期",
                endPlaceholder: "请选择结束日期",
                // rules: [
                //   {
                //     required: !this.isTractor,
                //     message: "请选择压力容器有效期",
                //     trigger: "change",
                //   },
                // ],
              },
            ],
          },
          {
            label: "资质附件",
            prop: "file",
            column: [
              {
                label: "牵引车行驶证照片",
                prop: "carTransportPic",
                hide: true,
                showColumn: false,
                display: !this.isTrailer,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                rules: [
                  {
                    required: !this.isTrailer,
                    message: "请上传牵引车行驶证照片",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "挂车行驶证照片",
                prop: "bindCarTransportPic",
                hide: true,
                showColumn: false,
                display: !this.isTractor,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                rules: [
                  {
                    required: this.isTrailer,
                    message: "请上传挂车行驶证照片",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "牵引车营运证照片",
                prop: "carWorkPic",
                hide: true,
                showColumn: false,
                display: !this.isTrailer,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                rules: [
                  {
                    required: !this.isTrailer,
                    message: "请上传牵引车营运证照片",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "挂车营运证照片",
                prop: "bindCarWorkPic",
                hide: true,
                showColumn: false,
                display: !this.isTractor,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                rules: [
                  {
                    required: this.isTrailer,
                    message: "请上传挂车营运证照片",
                    trigger: "change",
                  },
                ],
              },
              {
                label: "罐体报告照片",
                prop: "containerReportPic",
                hide: true,
                showColumn: false,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
                // rules: [
                //   {
                //     required: true,
                //     message: "请上传罐体报告照片",
                //     trigger: "change",
                //   },
                // ],
              },
              {
                label: "环保清单照片",
                prop: "protectionList",
                hide: true,
                showColumn: false,
                type: "upload",
                span: 12,
                listType: "picture-img",
                propsHttp: {
                  res: "data",
                  name: "originalName",
                  url: "link",
                },
                action: "/api/blade-resource/oss/endpoint/put-file-attach",
              },
            ],
          },
          {
            label: "车辆信息",
            prop: "carInfo",
            column: [
              {
                label: "车牌颜色",
                prop: "carColor",
                hide: true,
                showColumn: false,
              },
              {
                label: "最大载重（单位:TO）",
                prop: "maxLoad",
                hide: true,
                showColumn: false,
                rules: [{ validator: validateNum, trigger: "blur" }],
              },
              {
                label: "货箱容积（单位：M³）",
                prop: "maxCapacity",
                hide: true,
                showColumn: false,
                rules: [{ validator: validateNum, trigger: "blur" }],
              },
              {
                label: "长（单位：M）",
                prop: "attrD",
                hide: true,
                showColumn: false,
                rules: [{ validator: validateNum, trigger: "blur" }],
              },
              {
                label: "宽（单位：M）",
                prop: "attrW",
                hide: true,
                showColumn: false,
                rules: [{ validator: validateNum, trigger: "blur" }],
              },
              {
                label: "高（单位：M）",
                prop: "attrH",
                hide: true,
                showColumn: false,
                rules: [{ validator: validateNum, trigger: "blur" }],
              },
              {
                label: "紧急切断阀是否安装",
                prop: "esv",
                type: "radio",
                dicData: [
                  {
                    label: "是",
                    value: "是",
                  },
                  {
                    label: "否",
                    value: "否",
                  },
                ],
              },
              {
                label: "是否配备灭火器",
                prop: "fireOff",
                type: "radio",
                dicData: [
                  {
                    label: "是",
                    value: "是",
                  },
                  {
                    label: "否",
                    value: "否",
                  },
                ],
              },
            ],
          },
        ],
      };
    },
  },
  methods: {
    rowEdit(row, index) {
      this.$refs.crud.rowEdit(row, index);
      this.form = {
        ...row,
        certificationCarCheckValid: [
          row.certificationCarCheckValidStart,
          row.certificationCarCheckValidEnd,
        ],
        certificationBindCarCheckValid: [
          row.certificationBindCarCheckValidStart,
          row.certificationBindCarCheckValidEnd,
        ],
        certificationCarWorkValid: [
          row.certificationCarWorkValidStart,
          row.certificationCarWorkValidEnd,
        ],
        certificationBindCarWorkValid: [
          row.certificationBindCarWorkValidStart,
          row.certificationBindCarWorkValidEnd,
        ],
        vehicleInsuranceValid: [
          row.vehicleInsuranceValidStart,
          row.vehicleInsuranceValidEnd,
        ],
        containerReportValid: [
          row.containerReportValidStart,
          row.containerReportValidEnd,
        ],
        certificateTankTruckDate: [
          row.certificateTankTruckStart,
          row.certificateTankTruckEnd,
        ],
      };
    },
    //查看驳回原因
    viewReject(row) {
      this.$alert(row.remarkReject, "驳回原因", {
        showCancelButton: true,
        showConfirmButton: false,
        cancelButtonText: "关闭",
      });
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      if (this.query.expireDate) {
        this.query = {
          ...params,
          expireDate: this.query.expireDate,
        };
      } else {
        this.query = params;
      }
      // this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      let query = Object.assign(params, this.query);
      if (query.createTime) {
        query = {
          ...query,
          start: query.createTime ? query.createTime[0] : "",
          end: query.createTime ? query.createTime[1] : "",
        };
        delete query.createTime;
      }
      this.loading = true;
      getList(page.currentPage, page.pageSize, query).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.$nextTick(() => {
          this.$refs.crud.$refs.table.doLayout();
        });
      });
    },
    //编辑
    rowUpdate(row, index, done, loading) {
      let updateData = {
        ...row,
        //牵引车校验有效期
        certificationCarCheckValidStart: row.certificationCarCheckValid
          ? row.certificationCarCheckValid[0]
          : "",
        certificationCarCheckValidEnd: row.certificationCarCheckValid
          ? row.certificationCarCheckValid[1]
          : "",
        //挂车校验有效期
        certificationBindCarCheckValidStart: row.certificationBindCarCheckValid
          ? row.certificationBindCarCheckValid[0]
          : "",
        certificationBindCarCheckValidEnd: row.certificationBindCarCheckValid
          ? row.certificationBindCarCheckValid[1]
          : "",
        //牵引车营运证号有效期
        certificationCarWorkValidStart: row.certificationCarWorkValid
          ? row.certificationCarWorkValid[0]
          : "",
        certificationCarWorkValidEnd: row.certificationCarWorkValid
          ? row.certificationCarWorkValid[1]
          : "",
        //挂车营运证号有效期
        certificationBindCarWorkValidStart: row.certificationBindCarWorkValid
          ? row.certificationBindCarWorkValid[0]
          : "",
        certificationBindCarWorkValidEnd: row.certificationBindCarWorkValid
          ? row.certificationBindCarWorkValid[1]
          : "",
        //交强险有效期
        vehicleInsuranceValidStart: row.vehicleInsuranceValid
          ? row.vehicleInsuranceValid[0]
          : "",
        vehicleInsuranceValidEnd: row.vehicleInsuranceValid
          ? row.vehicleInsuranceValid[1]
          : "",
        //罐体报告有效期
        containerReportValidStart: row.containerReportValid
          ? row.containerReportValid[0]
          : "",
        containerReportValidEnd: row.containerReportValid
          ? row.containerReportValid[1]
          : "",
        //压力容器有效期
        certificateTankTruckStart: row.certificateTankTruckDate
          ? row.certificateTankTruckDate[0]
          : "",
        certificateTankTruckEnd: row.certificateTankTruckDate
          ? row.certificateTankTruckDate[1]
          : "",
      };
      update(updateData).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    //新增
    rowSave(form, done, loading) {
      let updateData = {
        ...form,
        //牵引车校验有效期
        certificationCarCheckValidStart: form.certificationCarCheckValid
          ? form.certificationCarCheckValid[0]
          : "",
        certificationCarCheckValidEnd: form.certificationCarCheckValid
          ? form.certificationCarCheckValid[1]
          : "",
        //挂车校验有效期
        certificationBindCarCheckValidStart: form.certificationBindCarCheckValid
          ? form.certificationBindCarCheckValid[0]
          : "",
        certificationBindCarCheckValidEnd: form.certificationBindCarCheckValid
          ? form.certificationBindCarCheckValid[1]
          : "",
        //牵引车营运证号有效期
        certificationCarWorkValidStart: form.certificationCarWorkValid
          ? form.certificationCarWorkValid[0]
          : "",
        certificationCarWorkValidEnd: form.certificationCarWorkValid
          ? form.certificationCarWorkValid[1]
          : "",
        //挂车营运证号有效期
        certificationBindCarWorkValidStart: form.certificationBindCarWorkValid
          ? form.certificationBindCarWorkValid[0]
          : "",
        certificationBindCarWorkValidEnd: form.certificationBindCarWorkValid
          ? form.certificationBindCarWorkValid[1]
          : "",
        //交强险有效期
        vehicleInsuranceValidStart: form.vehicleInsuranceValid
          ? form.vehicleInsuranceValid[0]
          : "",
        vehicleInsuranceValidEnd: form.vehicleInsuranceValid
          ? form.vehicleInsuranceValid[1]
          : "",
        //罐体报告有效期
        containerReportValidStart: form.containerReportValid
          ? form.containerReportValid[0]
          : "",
        containerReportValidEnd: form.containerReportValid
          ? form.containerReportValid[1]
          : "",
        //压力容器有效期
        certificateTankTruckStart: form.certificateTankTruckDate
          ? form.certificateTankTruckDate[0]
          : "",
        certificateTankTruckEnd: form.certificateTankTruckDate
          ? form.certificateTankTruckDate[1]
          : "",
      };
      loading();
      update(updateData).then(
        ({ data }) => {
          if (data.code === 200 && data.success) {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!",
            });
            done(updateData);
          } else if (data.code === 206) {
            this.$confirm("系统中已存在该车辆，是否进行绑定?", "提示", {
              confirmButtonText: "绑定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {
                phoneBind({
                  number:
                    updateData.carType === "trailer"
                      ? updateData.bindCarNo
                      : updateData.carNo,
                  type: updateData.carType === "trailer" ? "bindCar" : "car",
                }).then(
                  () => {
                    this.onLoad(this.page);
                    this.$message({
                      type: "success",
                      message: "操作成功!",
                    });
                    done(updateData);
                  },
                  (error) => {
                    window.console.log(error);
                  }
                );
              })
              .catch(() => {
                this.onLoad(this.page);
                done(updateData);
              });
          }
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    //删除
    rowDel(form) {
      this.delCar([form.id]);
    },
    //批量删除
    batchDelete() {
      if (this.selectionList.length <= 0) {
        this.$message({
          message: "请选择车辆",
          type: "warning",
        });
        return false;
      }
      let ids = this.selectionList.map((item) => {
        return item.id;
      });
      this.delCar(ids);
    },
    delCar(ids) {
      this.$confirm("是否确定删除所选车辆?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteCar({ ids: ids }).then(
            () => {
              this.onLoad(this.page);
              this.$message({
                type: "success",
                message: "操作成功!",
              });
            },
            (error) => {
              window.console.log(error);
            }
          );
        })
        .catch(() => {});
    },
    //多选
    selectionChange(list) {
      this.selectionList = list;
    },
  },
};
</script>

<style></style>
